package com.yyt2025.util;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;

public class FileExistenceChecker {

    private boolean checkExist(@NotNull PsiElement[] elements, String fullFileName ){
        for (PsiElement element : elements) {
            if (element instanceof PsiDirectory) {
                PsiDirectory directory = (PsiDirectory) element;
                String currName = directory.getName();
                if (fullFileName.indexOf(currName)==-1) {
                    continue;
                }
                String fileName = fullFileName.substring(fullFileName.lastIndexOf(currName)+currName.length());
                PsiElement[] children = directory.getChildren();
                for (PsiElement child : children) {
                    Class clzz = child.getClass();
                    if (child instanceof PsiDirectory) {
                        PsiDirectory childDirectory = (PsiDirectory) child;
                        String allName = childDirectory.getName();
                        if (fullFileName.indexOf(allName) == -1) {
                            continue;
                        }
                    }else {

                        if (child instanceof PsiFile){
                            PsiFile childFile = (PsiFile) child;
                            String allName = childFile.getName();
                            if (fullFileName.equals(allName)) {
                                return true;
                            }
                        }

                    }

                    return true;
                }
            }
            else {
                PsiFile file = element.getContainingFile();
                if (file == null) {
                    return false;
                }
                VirtualFile virtualFile = file.getVirtualFile();
                if (virtualFile == null) {
                    return false;
                }
            }
        }
        return false;
    }

}